package com.cheer.vo;

import com.cheer.entity.Applicant;
import com.cheer.entity.StandingBookReview;
import com.cheer.enums.RegisterStatusEnum;
import com.cheer.enums.ReviewStatusEnum;
import com.cheer.enums.TitleEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * @author cheer
 */
@Data
@Accessors(chain = true)
public class StatisticsVO {

    /**
     * 文明号集体总数
     */
    private Integer total;

    /**
     * 已申请文明号集体
     */
    private Integer apply;

    /**
     * 已获得文明号命名集体
     */
    private Integer passed;

    /**
     * 国家级青年文明号
     */
    private Integer nation;

    /**
     * 省级青年文明号
     */
    private Integer province;

    /**
     * 市级青年文明号
     */
    private Integer city;

    /**
     * 待审核注册集体
     */
    private Integer register;

    /**
     * 待审核创建备案集体
     */
    private Integer review;

    private Integer upgrade;

    public static StatisticsVO build(List<Applicant> applicants, List<StandingBookReview> standingBookReviews) {
        StatisticsVO statisticsVO = new StatisticsVO();
        statisticsVO.setTotal(applicants.size());
        statisticsVO.setApply((int) applicants.stream()
                .filter(applicant -> applicant.getTitle() == TitleEnum.NO.getType())
                .count());
        statisticsVO.setPassed((int) applicants.stream()
                .filter(applicant -> applicant.getTitle() > TitleEnum.NO.getType())
                .count());
        statisticsVO.setNation((int) applicants.stream()
                .filter(applicant -> applicant.getTitle() == TitleEnum.NATION.getType())
                .count());
        statisticsVO.setProvince((int) applicants.stream()
                .filter(applicant -> applicant.getTitle() == TitleEnum.PROVINCE.getType())
                .count());
        statisticsVO.setCity((int) applicants.stream()
                .filter(applicant -> applicant.getTitle() == TitleEnum.CITY.getType())
                .count());
        statisticsVO.setRegister((int) applicants.stream()
                .filter(applicant -> applicant.getRegisterStatus() < RegisterStatusEnum.CITY_TITLE.getCode())
                .count());
        statisticsVO.setReview((int) standingBookReviews.stream()
                .filter(standingBookReview -> standingBookReview.getReviewStatus() == ReviewStatusEnum.TO_REVIEW.getCode() ||
                        standingBookReview.getReviewStatus() == ReviewStatusEnum.UP_NOT_PASSED.getCode() ||
                        standingBookReview.getReviewStatus() == ReviewStatusEnum.NOT_PASSED_SUBMIT.getCode() ||
                        standingBookReview.getReviewStatus() == ReviewStatusEnum.REJECTED_SUBMIT.getCode()).count());
        statisticsVO.setUpgrade((int) applicants.stream()
                .filter(applicant -> applicant.getRegisterStatus() == RegisterStatusEnum.PROVINCE.getCode())
                .count());
        return statisticsVO;
    }

}
